import 'package:flutter/material.dart';

// ignore: must_be_immutable
abstract class BaseTestWidget extends StatefulWidget {
  _BaseTestWidgetState _state;
  BuildContext _context;
  get context => _context;

  @override
  _BaseTestWidgetState createState() {
    return _state = _BaseTestWidgetState();
  }

  String getTitle();

  Widget getBody(BuildContext context);

  void initState(){

  }

  void dispose(){

  }

  setState(VoidCallback fn){
    _state?.update(fn);
  }
}

class _BaseTestWidgetState extends State<BaseTestWidget> {
  update(VoidCallback fn){
    setState(fn);
  }

  @override
  void initState() {
    widget.initState();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    widget._context = context;
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.getTitle() ?? ""),
      ),
      body: widget.getBody(context),
    );
  }

  @override
  void dispose() {
    widget.dispose();
    super.dispose();
  }
}
